#include"SList.h"
void SLTTest1(void)
{
    SLTNode* plist = NULL;//创建一个空链表，以供后续插入结点
    //尾插
    SLTPushBack(&plist, 1);
    SLTPushBack(&plist, 2);
    SLTPushBack(&plist, 3);
    SLTPrint(plist);
    //头插
    SLTPushFront(&plist, 2);
    SLTPushFront(&plist, 3);
    SLTPrint(plist);
    //尾删
    SLTPopBack(&plist);
    SLTPrint(plist);
    //头删
    SLTPopFront(&plist);
    SLTPrint(plist);
    //查找
    SLTNode* find = SLTFind(plist, 2);
    if (find == NULL) {
        printf("没找到\n");
    }
    else
    {
        printf("找到了,是%d\n",find->x);
    }
    //在指定位置前插入数据
    SLTInsert(&plist,find, 3);
    SLTPrint(plist);
    SLTNode* find2 = SLTFind(plist, 1);
    //在指定位置之后插入数据
    SLTInsertAfter(find2, 12);
    SLTInsert(&plist,find2, 21);
    SLTPrint(plist);
    //删除指定位置数据
    SLTErase(&plist, find2);
    SLTPrint(plist);
    //删除指定位置之后的数据
    SLTEraseAfter(find);
    SLTPrint(plist);
    //销毁链表
    SLTDestroy(&plist);
    SLTPrint(plist);
}
//创建一个已包含数据的单链表
void SLTCreate(void)
{
    //申请一个结点空间大小的动态空间
    SLTNode* node1 = (SLTNode*)malloc(sizeof(SLTNode*));
    //然后直接插入数据
    node1->x = 1;
    SLTNode* node2 = (SLTNode*)malloc(sizeof(SLTNode*));
    SLTNode* node3 = (SLTNode*)malloc(sizeof(SLTNode*));
    SLTNode* node4 = (SLTNode*)malloc(sizeof(SLTNode*));
    node2->x = 2;
    node3->x = 3;
    node4->x = 4;
    //在把结点连接起来
    node1->next = node2;
    node2->next = node3;
    node3->next = node4;
    node4->next = NULL;
    //创建一个头结点指针指向头结点
    SLTNode* plist = node1;
    SLTPrint(plist);
}


int main()
{
    //SLTCreate();
    SLTTest1();
    return 0;
}
